/*Prepared Using STATA 19 MP: September 19, 2025*/
cap cd "C:\Users\ejm5\Dropbox\Vietnam Election project\2021_Election\Replication"
use "9_election_working.dta", clear
set scheme plottig

/***********************************************************************************************************/
/***********************************************************************************************************/
/*Appendix J: Sharp Null Test of Voting Results*/
reg Vote T1 T2 T3, cluster(votingdivision2) 
outreg2 using "Tables\AppendixJ", bdec(3) tdec(3) e(rmse N_clust) ctitle("Vote") label addtext("Block FE", Yes, "Major FE", Yes, "City FE", Yes, "Questionnaire_order", No) keep(T1 T2 T3) stats(coef pval) noaster replace
areg Vote T1 T2 T3 major1 major2 HCMC Questionnaire_order, cluster(votingdivision2) absorb(strata) 
outreg2 using "Tables\AppendixJ", bdec(3) tdec(3) e(rmse N_clust) ctitle("Vote") label addtext("Block FE", Yes, "Major FE", Yes, "City FE", Yes, "Questionnaire_order", No) keep(T1 T2 T3) stats(coef pval) noaster excel

/********Randomization Inference***************/
/*log using "Tables\AppendixJ.smcl", replace*/
ritest T1 _b[T1],  kdensityplot reps(1000) seed(125) strata(strata): reg Vote T1 T2 T3, cluster(votingdivision2) 
ritest T2 _b[T2],  kdensityplot reps(1000) seed(125) strata(strata): reg Vote T1 T2 T3, cluster(votingdivision2)
ritest T3 _b[T3],  kdensityplot reps(1000) seed(125) strata(strata): reg Vote T1 T2 T3, cluster(votingdivision2)  

ritest T1 _b[T1],  kdensityplot reps(1000) seed(125) strata(strata): areg Vote T1 T2 T3 major1 major2 HCMC Questionnaire_order, cluster(votingdivision2) absorb(strata) 
ritest T2 _b[T2],  kdensityplot reps(1000) seed(125) strata(strata): areg Vote T1 T2 T3 major1 major2 HCMC Questionnaire_order, cluster(votingdivision2) absorb(strata) 
ritest T3 _b[T3],  kdensityplot reps(1000) seed(125) strata(strata): areg Vote T1 T2 T3 major1 major2 HCMC Questionnaire_order, cluster(votingdivision2) absorb(strata) 
/*log close*/
/***********************************************************************************************************/
/***********************************************************************************************************/
/*Appendix K.1 Direct and Proxy Voting: Full Regression Results for Figure 2*/

reg vote_directly T1 T2 T3, cluster(votingdivision2)
outreg2 using "Tables\AppendixK1", bdec(3) tdec(3) e(rmse N_clust) ctitle("Vote Directly==1") label addtext("Block FE", No, "Major FE", No, "City FE", No, "Questionnaire_order", No) keep(T1 T2 T3) stats(coef pval) noaster replace
areg vote_directly T1 T2 T3 major1 major2 HCMC Questionnaire_order, cluster(votingdivision2) absorb(strata)
outreg2 using "Tables\AppendixK1", bdec(3) tdec(3) e(rmse N_clust) ctitle("Vote Directly==1") label addtext("Block FE", Yes, "Major FE", Yes, "City FE", Yes, "Questionnaire_order", Yes)  keep(T1 T2 T3) stats(coef pval) noaster

reg vote_proxy T1 T2 T3, cluster(votingdivision2)
outreg2 using "Tables\AppendixK1", bdec(3) tdec(3) e(rmse N_clust) ctitle("Vote by Proxy==1") label addtext("Block FE", No, "Major FE", No, "City FE", No, "Questionnaire_order", Yes) keep(T1 T2 T3) stats(coef pval) noaster
areg vote_proxy T1 T2 T3 major1 major2 HCMC Questionnaire_order, cluster(votingdivision2) absorb(strata)
outreg2 using "Tables\AppendixK1", bdec(3) tdec(3) e(rmse N_clust) ctitle("Vote by Proxy==1") label addtext("Block FE", Yes, "Major FE", Yes, "City FE", Yes, "Questionnaire_order", Yes) keep(T1 T2 T3) stats(coef pval) noaster excel

/********Wild Bootstrap*****************************/
/*log using "Tables\TableK1.smcl", replace*/
wildbootstrap reg vote_directly T1 T2 T3, cluster(votingdivision2) rseed(11062024)
wildbootstrap areg vote_directly T1 T2 T3 major1 major2 HCMC Questionnaire_order, cluster(votingdivision2) absorb(strata) rseed(11062024)
wildbootstrap reg vote_proxy T1 T2 T3, cluster(votingdivision2) rseed(11062024)
wildbootstrap areg vote_proxy T1 T2 T3 major1 major2 HCMC Questionnaire_order, cluster(votingdivision2) absorb(strata) rseed(11062024)
/*log close*/
/***********************************************************************************************************/
/***********************************************************************************************************/
/*Appendix K2: Full Regression Results for Figure 3*/
wildbootstrap reg Vote i.T1##i.polibg  i.T2##i.polibg  i.T3##i.polibg   major1 major2 HCMC Question, cluster(votingdivision2) rseed(11062024)
outreg2 using "Tables\AppendixK2", bdec(3) tdec(3) e(rmse N_clust) ctitle("Vote") label addtext("Block FE", Yes, "Major FE", Yes, "City FE", Yes, "Questionnaire_order", Yes) keep(1.T1  1.polibg  1.T1#1.polibg 1.T2  1.T2#1.polibg 1.T3  1.T3#1.polibg ) stats(coef pval)  noaster  replace
wildbootstrap reg vote_directly i.T1##i.polibg  i.T2##i.polibg  i.T3##i.polibg   major1 major2 HCMC Question, cluster(votingdivision2) rseed(11062024)
outreg2 using "Tables\AppendixK2", bdec(3) tdec(3) e(rmse N_clust) ctitle("Vote Directly") label addtext("Block FE", Yes, "Major FE", Yes, "City FE", Yes, "Questionnaire_order", Yes)  keep(1.T1  1.polibg  1.T1#1.polibg 1.T2  1.T2#1.polibg 1.T3  1.T3#1.polibg ) stats(coef pval) noaster  
wildbootstrap reg vote_proxy i.T1##i.polibg  i.T2##i.polibg  i.T3##i.polibg   major1 major2 HCMC Question, cluster(votingdivision2) rseed(11062024)
outreg2 using "Tables\AppendixK2", bdec(3) tdec(3) e(rmse N_clust) ctitle("Vote by Proxy") label addtext("Block FE", Yes, "Major FE", Yes, "City FE", Yes, "Questionnaire_order", Yes)  keep(1.T1  1.polibg  1.T1#1.polibg 1.T2  1.T2#1.polibg 1.T3  1.T3#1.polibg ) stats(coef pval) noaster
wildbootstrap reg Vote i.T1##i.polistat  i.T2##i.polistat  i.T3##i.polistat   major1 major2 HCMC Question, cluster(votingdivision2) rseed(11062024)
outreg2 using "Tables\AppendixK2", bdec(3) tdec(3) e(rmse N_clust) ctitle("Vote") label addtext("Block FE", Yes, "Major FE", Yes, "City FE", Yes, "Questionnaire_order", Yes)  keep(1.T1  1.polistat  1.T1#1.polistat 1.T2  1.T2#1.polistat 1.T3  1.T3#1.polistat ) stats(coef pval) noaster  
wildbootstrap reg vote_directly i.T1##i.polistat  i.T2##i.polistat  i.T3##i.polistat   major1 major2 HCMC Question, cluster(votingdivision2) rseed(11062024)
outreg2 using "Tables\AppendixK2", bdec(3) tdec(3) e(rmse N_clust) ctitle("Vote Directly") label addtext("Block FE", Yes, "Major FE", Yes, "City FE", Yes, "Questionnaire_order", Yes)   keep(1.T1  1.polistat  1.T1#1.polistat 1.T2  1.T2#1.polistat 1.T3  1.T3#1.polistat ) stats(coef pval) noaster 
wildbootstrap reg vote_proxy i.T1##i.polistat  i.T2##i.polistat  i.T3##i.polistat   major1 major2 HCMC Question, cluster(votingdivision2) rseed(11062024)
outreg2 using "Tables\AppendixK2", bdec(3) tdec(3) e(rmse N_clust) ctitle("Vote by Proxy") label addtext("Block FE", Yes, "Major FE", Yes, "City FE", Yes, "Questionnaire_order", Yes)  keep(1.T1  1.polistat  1.T1#1.polistat 1.T2  1.T2#1.polistat 1.T3  1.T3#1.polistat ) stats(coef pval) noaster excel
/***********************************************************************************************************/
/***********************************************************************************************************/
/*Appendix K3: Full Regression Results for Figure 4*/
wildbootstrap reg VNALegitimacy_all i.T1##i.polibg  i.T2##i.polibg  i.T3##i.polibg   major1 major2 HCMC Question,  cluster(votingdivision2) rseed(11062024)
outreg2 using "Tables\AppendixK3", bdec(3) tdec(3) e(rmse N_clust) ctitle("Will Watch VNA=1") label addtext("Block FE", Yes, "Major FE", Yes, "City FE", Yes, "Questionnaire_order", Yes) keep(1.T1  1.polibg  1.T1#1.polibg 1.T2  1.T2#1.polibg 1.T3  1.T3#1.polibg ) stats(coef pval) noaster replace
wildbootstrap reg VNAConfidence_all i.T1##i.polibg  i.T2##i.polibg  i.T3##i.polibg   major1 major2 HCMC Question,  cluster(votingdivision2) rseed(11062024)
outreg2 using "Tables\AppendixK3", bdec(3) tdec(3) e(rmse N_clust) ctitle("Confidence in VNA (1-10)") label addtext("Block FE", Yes, "Major FE", Yes, "City FE", Yes, "Questionnaire_order", Yes)  keep(1.T1  1.polibg  1.T1#1.polibg 1.T2  1.T2#1.polibg 1.T3  1.T3#1.polibg ) stats(coef pval) noaster 
wildbootstrap reg VNALegitimacy_all i.T1##i.polistat  i.T2##i.polistat  i.T3##i.polistat   major1 major2 HCMC Question, cluster(votingdivision2) rseed(11062024)
outreg2 using "Tables\AppendixK3", bdec(3) tdec(3) e(rmse N_clust) ctitle("Will Watch VNA=1") label addtext("Block FE", Yes, "Major FE", Yes, "City FE", Yes, "Questionnaire_order", Yes) keep(1.T1  1.polistat  1.T1#1.polistat 1.T2  1.T2#1.polistat 1.T3  1.T3#1.polistat ) stats(coef pval) noaster 
wildbootstrap reg VNAConfidence_all i.T1##i.polistat  i.T2##i.polistat  i.T3##i.polistat   major1 major2 HCMC Question,  cluster(votingdivision2) rseed(11062024)
outreg2 using "Tables\AppendixK3", bdec(3) tdec(3) e(rmse N_clust) ctitle("Confidence in VNA (1-10)") label addtext("Block FE", Yes, "Major FE", Yes, "City FE", Yes, "Questionnaire_order", Yes) keep(1.T1  1.polistat  1.T1#1.polistat 1.T2  1.T2#1.polistat 1.T3  1.T3#1.polistat ) stats(coef pval) noaster excel
/***********************************************************************************************************/
/***********************************************************************************************************/
/*Appendix L.1 Effects of Having an Under-40 Candidate on Ballot*/
/*Age below 40*/
generate age40_dich=0
replace age40_dich=1 if AgeOver40<5 & AgeOver40 !=.
lab var age40_dich "Age Below 40=1"
label define age40_dich 1 "Yes" 0 "No", replace
label val age40_dich age40_dich

/*Interaction*/
reg Vote i.T1##i.age40_dich  i.T2##i.age40_dich  i.T3##i.age40_dich   major1 major2 HCMC Question , robust
margins, dydx(T1) by(age40_dich ) level(95)
marginsplot, recast(scatter) xtitle("", size(medium)) ytitle("", size(medium)) title("T1: Civic Education", position(12) span) yline(0, lcolor(red) lpattern(dash) lwidth(thin))  ciopts(lcolor(navy) lwidth(medthick))
graph save "Figures\margins_T1.gph", replace

reg Vote i.T1##i.age40_dich  i.T2##i.age40_dich  i.T3##i.age40_dich   major1 major2 HCMC Question , robust
margins, dydx(T2) by(age40_dich ) level(95)
marginsplot, recast(scatter) xtitle("", size(medium)) ytitle("", size(medium)) title("T2: Candidate Quality", position(12) span) yline(0, lcolor(red) lpattern(dash) lwidth(thin))  ciopts(lcolor(navy) lwidth(medthick))
graph save "Figures\margins_T2.gph", replace

reg Vote i.T1##i.age40_dich  i.T2##i.age40_dich  i.T3##i.age40_dich   major1 major2 HCMC Question , robust
margins, dydx(T3) by(age40_dich ) level(95)
marginsplot, recast(scatter) xtitle("", size(medium)) ytitle("", size(medium)) title("T3: Policy Objectives", position(12) span) yline(0, lcolor(red) lpattern(dash) lwidth(thin))  ciopts(lcolor(navy) lwidth(medthick))
graph save "Figures\margins_T3.gph", replace

graph combine "Figures\margins_T1.gph" "Figures\margins_T2.gph" "Figures\margins_T3.gph",xcommon imargin(tiny) title("Young Candidates", size(medium) position(6)) subtitle("Conditional Average Treatment Effects", position(9) orientation(vertical) size(medium)) rows(1)  
graph save "Figures\AppendixL1.gph", replace
graph export "Figures\AppendixL1.pdf", as(pdf) replace

/***********************************************************************************************************/
/***********************************************************************************************************/
/*Appendix L2 Effects of Having Woman Candidate on Ballot*/
/*Female Candidates on Ballot*/
generate female_dich=Female
replace female_dich=1 if Female>0 & Female !=.
lab var female_dich "Female Candidate on Ballot=1"
label define female_dich 1 "Yes" 0 "No",replace
label val female_dich female_dich

/*Interaction*/
reg Vote i.T1##i.female_dich  i.T2##i.female_dich  i.T3##i.female_dich   major1 major2 HCMC Question , robust
margins, dydx(T1) by(female_dich ) level(95)
marginsplot, recast(scatter) xtitle("", size(medium)) ytitle("", size(medium)) title("T1: Civic Education", position(12) span) yline(0, lcolor(red) lpattern(dash) lwidth(thin))  ciopts(lcolor(navy) lwidth(medthick))
graph save "Figures\margins_T1.gph", replace

reg Vote i.T1##i.female_dich  i.T2##i.female_dich  i.T3##i.female_dich   major1 major2 HCMC Question , robust
margins, dydx(T2) by(female_dich ) level(95)
marginsplot, recast(scatter) xtitle("", size(medium)) ytitle("", size(medium)) title("T2: Candidate Quality", position(12) span) yline(0, lcolor(red) lpattern(dash) lwidth(thin))  ciopts(lcolor(navy) lwidth(medthick))
graph save "Figures\margins_T2.gph", replace

reg Vote i.T1##i.female_dich  i.T2##i.female_dich  i.T3##i.female_dich   major1 major2 HCMC Question , robust
margins, dydx(T3) by(female_dich ) level(95)
marginsplot, recast(scatter) xtitle("", size(medium)) ytitle("", size(medium)) title("T3: Policy Objectives", position(12) span) yline(0, lcolor(red) lpattern(dash) lwidth(thin))  ciopts(lcolor(navy) lwidth(medthick))
graph save "Figures\margins_T3.gph", replace

graph combine "Figures\margins_T1.gph" "Figures\margins_T2.gph" "Figures\margins_T3.gph",xcommon imargin(tiny) title("Women Candidates", size(medium) position(6)) subtitle("Conditional Average Treatment Effects", position(9) orientation(vertical) size(medium)) rows(1)  
graph save "Figures\AppendixL2.gph", replace
graph export "Figures\AppendixL2.pdf", as(pdf) replace

/***********************************************************************************************************/
/***********************************************************************************************************/
/*Appendix L3 Effects of Having Woman Candidate on Ballot*/
/*Non-Party*/
generate VCP_dich=0
replace VCP_dich=1 if VCPMember<5 & VCPMember !=.
lab var VCP_dich "NonVCP member=1"
label define VCP_dich 1 "Yes" 0 "No",replace
label val VCP_dich VCP_dich

/*Interaction*/
reg Vote i.T1##i.VCP_dich  i.T2##i.VCP_dich  i.T3##i.VCP_dich   major1 major2 HCMC Question , robust
margins, dydx(T1) by(VCP_dich ) level(95)
marginsplot, recast(scatter) xtitle("", size(medium)) ytitle("", size(medium)) title("T1: Civic Education", position(12) span) yline(0, lcolor(red) lpattern(dash) lwidth(thin))  ciopts(lcolor(navy) lwidth(medthick))
graph save "Figures\margins_T1.gph", replace

reg Vote i.T1##i.VCP_dich  i.T2##i.VCP_dich  i.T3##i.VCP_dich   major1 major2 HCMC Question , robust
margins, dydx(T2) by(VCP_dich ) level(95)
marginsplot, recast(scatter) xtitle("", size(medium)) ytitle("", size(medium)) title("T2: Candidate Quality", position(12) span) yline(0, lcolor(red) lpattern(dash) lwidth(thin))  ciopts(lcolor(navy) lwidth(medthick))
graph save "Figures\margins_T2.gph", replace

reg Vote i.T1##i.VCP_dich  i.T2##i.VCP_dich  i.T3##i.VCP_dich   major1 major2 HCMC Question , robust
margins, dydx(T3) by(VCP_dich ) level(95)
marginsplot, recast(scatter) xtitle("", size(medium)) ytitle("", size(medium)) title("T3: Policy Objectives", position(12) span) yline(0, lcolor(red) lpattern(dash) lwidth(thin))  ciopts(lcolor(navy) lwidth(medthick))
graph save "Figures\margins_T3.gph", replace

graph combine "Figures\margins_T1.gph" "Figures\margins_T2.gph" "Figures\margins_T3.gph",xcommon imargin(tiny) title("Non-Party Candidates", size(medium) position(6)) subtitle("Conditional Average Treatment Effects", position(9) orientation(vertical) size(medium)) rows(1)  
graph save "Figures\AppendixL3.gph", replace
graph export "Figures\AppendixL3.pdf", as(pdf) replace

/***********************************************************************************************************/
/***********************************************************************************************************/
/*Appendix L4 Effects of Having Woman Candidate on Ballot*/
/*VNA incumbency*/
generate Incumbent_dich=0
replace Incumbent_dich=1 if IncumbentVNA>1 & IncumbentVNA !=.
lab var Incumbent_dich "Incumbent VNA member=1"
label define Incumbent_dich 1 "Yes" 0 "No",replace
label val Incumbent_dich Incumbent_dich


/*Interaction*/
reg Vote i.T1##i.Incumbent_dich  i.T2##i.Incumbent_dich  i.T3##i.Incumbent_dich   major1 major2 HCMC Question , robust
margins, dydx(T1) by(Incumbent_dich ) level(95)
marginsplot, recast(scatter) xtitle("", size(medium)) ytitle("", size(medium)) title("T1: Civic Education", position(12) span) yline(0, lcolor(red) lpattern(dash) lwidth(thin))  ciopts(lcolor(navy) lwidth(medthick))
graph save "Figures\margins_T1.gph", replace

reg Vote i.T1##i.Incumbent_dich  i.T2##i.Incumbent_dich  i.T3##i.Incumbent_dich   major1 major2 HCMC Question , robust
margins, dydx(T2) by(Incumbent_dich ) level(95)
marginsplot, recast(scatter) xtitle("", size(medium)) ytitle("", size(medium)) title("T2: Candidate Quality", position(12) span) yline(0, lcolor(red) lpattern(dash) lwidth(thin))  ciopts(lcolor(navy) lwidth(medthick))
graph save "Figures\margins_T2.gph", replace

reg Vote i.T1##i.Incumbent_dich  i.T2##i.Incumbent_dich  i.T3##i.Incumbent_dich   major1 major2 HCMC Question , robust
margins, dydx(T3) by(Incumbent_dich ) level(95)
marginsplot, recast(scatter) xtitle("", size(medium)) ytitle("", size(medium)) title("T3: Policy Objectives", position(12) span) yline(0, lcolor(red) lpattern(dash) lwidth(thin))  ciopts(lcolor(navy) lwidth(medthick))
graph save "Figures\margins_T3.gph", replace


graph combine "Figures\margins_T1.gph" "Figures\margins_T2.gph" "Figures\margins_T3.gph",xcommon imargin(tiny) title("Incumbents", size(medium) position(6)) subtitle("Conditional Average Treatment Effects", position(9) orientation(vertical) size(medium)) rows(1)  
graph save "Figures\AppendixL4.gph", replace
graph export "Figures\AppendixL4.pdf", as(pdf) replace
